package org.naigu.peach.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import org.naigu.peach.dal.dao.SubjectDAO;
import org.naigu.peach.dal.dataobject.SubjectDO;
import guda.grape.autogen.common.page.BaseQuery;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SubjectDAOImpl extends BaseDAO implements SubjectDAO {

    @Override
	public Long insert(SubjectDO subject) {
	      try {
                return (Long) getSqlMapperW().insert("subject.insert",subject);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public SubjectDO getSubjectById(Long subjectId) {
	    return (SubjectDO)getSqlMapClientTemplate().queryForObject("subject.getSubjectById", subjectId);
	}

    @Override
	public boolean delSubjectById(Long subjectId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("subject.delSubjectById",subjectId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<SubjectDO> getSubjectByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("subject.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long subjectId) {
	    try {
            getSqlMapperW().update("subject.cleanAutoIncrement",subjectId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<SubjectDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("subject.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("subject.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(SubjectDO subject) {
        try {
            getSqlMapperW().update("subject.updateByIdSelective",subject);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}

